// Autocompletion and template data.

var headerNames = [
    "Access-Control-Allow-Origin", "Age", "Allow", "Cache-Control",
    "Connection", "Content-Encoding", "Content-Language", "Content-Length",
    "Content-Location", "Content-MD5", "Content-Range", "Content-Type", "Date",
    "ETag", "Expires", "Last-Modified", "Location", "Pragma", "Retry-After",
    "Server", "Set-Cookie", "Trailer", "Transfer-Encoding", "Upgrade", "Vary",
    "Via", "Warning", "WWW-Authenticate",
];

var headerValues = {
    "content-encoding": [ "gzip", "compress", "deflate", "identity" ],
    "content-type":
        addPrefix("application/", [
            "atom+xml", "atomcat+xml", "atomsvc+xml", "javascript", "json",
            "octet-stream", "rdf+xml", "rss+xml", "soap+xml",
            "sparql-results+xml", "wsdl+xml", "xhtml+xml", "xml", "xslt+xml"
        ]).concat(addPrefix("text/", [
            "css", "csv", "html", "javascript", "n3", "plain", "turtle", "xml"
        ])),
};

var now = (new Date()).getTime();
var headerDefaults = {
    "access-control-allow-origin": "*",
    "allow": "GET, HEAD",
    "cache-control": "no-cache",
    "content-encoding": "identity",
    "content-language": "en",
    "content-type": "text/html",
    "date": dateToRFC822(new Date(now)),
    "expires": dateToRFC822(new Date(now + 3600000)),        // +1 hour
    "last-modified": dateToRFC822(new Date(now - 3600000)),  // −1 hour
    "pragma": "no-cache",
    "set-cookie": "hello=world; max-age=3600",
    "vary": "Cookie",
    "www-authenticate": 'Basic realm="mockup"',
};

var bodyDefaults = {
    "application/atom+xml":
        '<?xml version="1.0"?>\n' +
        '<feed xmlns="http://www.w3.org/2005/Atom">\n</feed>',
    
    "application/atomcat+xml":
        '<?xml version="1.0"?>\n' +
        '<categories xmlns="http://www.w3.org/2007/app">\n</categories>',
    
    "application/atomsvc+xml":
        '<?xml version="1.0"?>\n' +
        '<service xmlns="http://www.w3.org/2007/app">\n</service>',
    
    "application/json":
        '{\n"id": 1\n}',
    
    "application/rdf+xml":
        '<?xml version="1.0"?>\n' +
        '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n' +
        '</rdf:RDF>',
    
    "application/rss+xml":
        '<?xml version="1.0"?>\n<rss version="2.0">\n</rss>',
    
    "application/sparql-results+xml":
        '<?xml version="1.0"?>\n' +
        '<sparql xmlns="http://www.w3.org/2005/sparql-results#">\n' +
        '<head>\n<variable name="s"/>\n<variable name="p"/>\n' +
        '<variable name="o"/>\n</head>\n<results>\n</results>\n</sparql>',
    
    "application/xhtml+xml":
        '<?xml version="1.0"?>\n' +
        '<html xmlns="http://www.w3.org/1999/xhtml">\n' +
        '<body>\n<p>Hello world!</p>\n</body>\n</html>',
    
    "application/xml":
        '<?xml version="1.0"?>\n<root>\n</root>',
    
    "application/xslt+xml":
        '<?xml version="1.0"?>\n' +
        '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">\n' +
        '</xsl:stylesheet>',
    
    "text/css":
        'body {\n}',
    
    "text/csv":
        'hello,world',
    
    "text/html":
        '<html>\n<body>\n<p>Hello world!</p>\n</body>\n</html>',
    
    "text/n3":
        '@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n' +
        '<> rdfs:label "Hello world" .',
    
    "text/plain":
        'Hello, world!',
    
    "text/turtle":
        '@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n' +
        '<> rdfs:label "Hello world" .',
    
    "text/xml":
        '<?xml version="1.0"?>\n<root>\n</root>',
};

var target = window.location.href.replace(/\/inspect\/$/, "/mock/target");
var templates = {
    html: {
        caption: "HTML document",
        status: 200,
        headers: {
            "Content-Type": "text/html; charset=utf-8",
            "Content-Language": "en",
        },
        body: bodyDefaults["text/html"]
    },
    
    xml: {
        caption: "XML document",
        status: 200,
        headers: {
            "Content-Type": "text/xml; charset=utf-8",
        },
        body: bodyDefaults["text/xml"]
    },
    
    json: {
        caption: "JSON object",
        status: 200,
        headers: {
            "Content-Type": "application/json",
        },
        body: bodyDefaults["application/json"]
    },
    
    redir: {
        caption: "Redirection",
        status: 303,
        headers: {
            "Location": target,
            "Content-Type": "text/html; charset=utf-8",
        },
        body: '<html>\n<body>\n<p>See <a href="' + target + 
              '">other</a>.</p>\n</body>\n</html>'
    },
}
